/**
 * 
 */
package com.lgf.extdemo.pojo;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author Ext 树结构
 *
 */
public class Tree {
	private int id;
	private int pid;
	private String text;
	private boolean leaf;
	private String iconCls;
	private String href;
	private boolean showLeaf ; 

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getPid() {
		return pid;
	}
	public void setPid(int pid) {
		this.pid = pid;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public boolean isLeaf() {
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	public String getIconCls() {
		return iconCls;
	}
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}
	public String getHref() {
		return href;
	}
	public void setHref(String href) {
		this.href = href;
	}
	public boolean isShowLeaf() {
		return showLeaf;
	}
	public void setShowLeaf(boolean showLeaf) {
		this.showLeaf = showLeaf;
	}
	
	// 解析成JsonObject
	public void parseToJson(JSONObject obj){
		obj.put("id", this.id);
		obj.put("pid", this.pid);
		obj.put("text", this.text);
		
		// 路径
		if (this.href != null) {
			obj.put("href", this.href);
		}
		
		// 样式
		if (this.iconCls != null) {
			obj.put("iconCls", this.iconCls);
		}
		
		// 是否显示叶子
		if (this.showLeaf) {
			obj.put("leaf", this.leaf);
		}else if(this.leaf){
			obj.put("children",new JSONArray());
		}
	}
}
